<?php
namespace app\index\controller\wanlshop;
use fast\Http;
use think\Controller;
use think\Db;

/**
 * 全境供应链消息回调类
 *
 * @icon   fa fa-cogs
 * @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
 */
class Message extends Controller
{

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 全境供应链消息回调方法
     */
    public function index()
    {
        /*
         * post接收到的参数结构如下
         * {
         * "messageId":"109040085",
         * "appKey":"1861258982681595906",
         * "enumNum":"10",
         * "content":"{\"spuId\":1846079303731507201}",
         * "createTime":"2024-12-16 09:56:56",
         * "sign":"bff5dc99f226c9fdfeaed2a999420656"
         * }
         */
      $this->request->filter(['strip_tags']);
      if($this->request->isPost()){
          $postData=$this->request->post();
          file_put_contents('sceApi_message.log',date('Y-m-d H:i:s').PHP_EOL.json_encode($postData).PHP_EOL.PHP_EOL.PHP_EOL,FILE_APPEND);
          if(!$postData) file_put_contents('sceApi_message.log',date('Y-m-d H:i:s').PHP_EOL.'未接收到参数'.PHP_EOL.PHP_EOL.PHP_EOL,FILE_APPEND);
          if(!is_array($postData) || !isset($postData['enumNum']) ||
          !isset($postData['content'])) file_put_contents('sceApi_message.log',date('Y-m-d H:i:s').PHP_EOL.'参数错误'.PHP_EOL.PHP_EOL.PHP_EOL,FILE_APPEND);

          $enumNum=$postData['enumNum'];
          $content=$postData['content'];
          $content=json_decode($content,true);

          //print_r($enumNum);echo '<br/>';
          //print_r($content);echo '<br/>';
          //print_r($postData);echo '<br/><br/><br/>';
          $this->doAction($enumNum,$content);
          $this->success('操作成功');
      }else{
          //$this->test();
          $this->error('非法请求');
      }
    }


    //测试录入商品发货信息

    public function test(){
        $content='{"orderSn":"PO130564866068710","origStatus":1,"origStatusName":"待卖家审核","returnSn":"SH9652746799","status":3,"statusName":"退款成功"}';
        $content=json_decode($content,true);
        $this->doAction(3,$content);
    }


    //测试退款
    public function testRefund(){
        $refund=model('app\admin\model\wanlshop\Refund')::get(80);
        $result=refund($refund);
        print_r($result);
    }

    /**
     * @param int $enumNum 消息的枚举值
     * @param array $content 消息内容
     * @return void
     */
    private function doAction(int $enumNum,array $content){

        $log=['type'=>'','enum_code'=>$enumNum,'content'=>json_encode($content,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE),'result'=>''];

        switch ($enumNum){
            //订单类消息类型
            case 1://订单状态变更通知,{"orderSn":"PO843671026667662","origStatus":20,"origStatusName":"待发货","status":30,"statusName":"待收货"}
                $log['type']='订单状态变更通知';
                $order=model('app\api\model\wanlshop\Order')
                    ->where('cloud_order_no',$content['orderSn'])
                    ->where('status','normal')
                    ->find();
                if($order){
                    //全境供应链云-查询订单详情
                    $result=getOrderDetail($order,$content['status']);
                    $log['result']=isset($result['code'])?$result['msg'].';':'订单状态变更成功;';
                }else{
                    $log['result']="订单状态变更失败:订单不存在,云订单号={$content['orderSn']};";
                }
            case 2://订单商品发货通知,{"deliveryCorpSn":"yuantong","deliverySn":"YT123456789","orderSn":"PO843671026667662","skuIdList":["1401883604734230530", "1410044831297241090"]}
                $log['type']='订单商品发货通知';
                $order=model('app\api\model\wanlshop\Order')
                    ->where('cloud_order_no',$content['orderSn'])
                    ->where('status','normal')
                    ->find();
                if($order){
                    $order['express_name']=getExpressNameByDeliveryCorpSn($content['deliveryCorpSn'])['qj_name'];
                    $order['express_code']=$content['deliveryCorpSn'];
                    $order['express_no']=$content['deliverySn'];
                    $order['delivertime']=time();
                    $affect=$order->allowField(true)->save();
                    $log['result']=$affect?'订单发货状态更新成功;':'订单发货状态更新失败;';
                    //如果没有录入,则把订单发货信息录入微信商户平台
                    if(!$order['mch_platform_status']){
                        $result = $this->uploadShippingInfo($order);
                        if ($result['code'] == 0) {//成功
                            $log['result'] .= '小程序发货信息上传成功;';
                            $order['mch_platform_status'] = 1;
                            $affect = $order->allowField(true)->save();
                            $log['result'] .= $affect ? '状态更新成功;' : ',状态更新失败;';
                        } else {//失败
                            $log['result'] .= '小程序发货信息上传失败;:'.$result['msg'].';';
                        }
                    }
                }else{
                    $log['result']="失败:需发货的订单不存在,云订单号={$content['orderSn']};";
                }
                break;
            case 3://售后订单状态变更通知,{"orderSn":"PO843671026667662","origStatus":1,"origStatusName":"待卖家审核","returnSn":"SH4972445524","status":1,"statusName":"待卖家审核"}
                $log['type']='售后订单状态变更通知';
                $order=model('app\api\model\wanlshop\Order')
                    ->where('cloud_order_no',$content['orderSn'])
                    ->where('status','normal')
                    ->find();

                $refund_order=$order?model('app\api\model\wanlshop\Refund')
                    ->where('order_id',$order['id'])
                    ->where('cloud_returnSn',$content['returnSn'])
                    ->find():null;

                if($refund_order) {
                    //$content['status']=3,9,18,表示本次回调是完成退款操作,保险起见,对退款单的状态做个检查
                    if(in_array($content['status'],[3,9,18]) && $refund_order['status']==4){
                        $log['result']="[严重]-退款行为被终止:本次通知是完成退款操作,退款单在此之前状态已为'完成退款',因此终止本次退款操作,请检查;";
                    }else {
                        $resp = [
                            'returnType' => $refund_order['type'] + 1,
                            'returnStatus' => $content['status']
                        ];
                        $refund_order = buildRefundState($refund_order, $resp, false);
                        $result = $refund_order->allowField(true)->save();
                        $log['result'] = $result ? "售后订单状态变更成功,变更结果为{$result}(1表示成功);" : "售后订单状态变更失败,变更结果为{$result}(0表示无变更);";
                        //如果全境完成退款，则执行退款操作,state=4表示退款成功
                        if ($refund_order->state == 4) {
                            //3和18代表全境退款完成,则执行商户平台退款
                            $log['result'] .= '开始退款操作:';
                            $result = refund($refund_order);
                            $log['result'] .= $result['msg'] . ';';
                        }
                    }
                }else{
                    $log['result']=$order?"失败:订单ID={$order['id']},退货单不存在,退货单云端号{$content['returnSn']};":"失败:云端订单号={$content['orderSn']},订单不存在,退货单不存在;";
                }
                break;
            case 20://订单支付成功通知,{"orderSn":"PO843671026667662","origStatus":10,"origStatusName":"待支付","status":10,"statusName":"待支付"}
                $log['type']='订单支付成功通知';
                $order=model('app\api\model\wanlshop\Order')
                    ->where('cloud_order_no',$content['orderSn'])
                    ->where('status','normal')
                    ->find();
                if($order){
                    //全境供应链云-查询订单详情
                    $result=getOrderDetail($order,$content['status']);
                    $log['result']=isset($result['code'])?$result['msg'].';':'订单状态变更成功;';
                }else{
                    $log['result']='订单状态变更失败:订单不存在;';
                }
                break;
            case 21://订单商品修改发货信息,{"deliveryCorpSn":"yuantong","deliverySn":"yt123456789","orderSn":"PO843671026667662","skuIdList":["1410044831297241090"]}
                $log['type']='订单商品修改发货信息';
                $order=model('app\api\model\wanlshop\Order')
                    ->where('cloud_order_no',$content['orderSn'])
                    ->where('status','normal')
                    ->find();
                if($order){
                    $order['express_name']=getExpressNameByDeliveryCorpSn($content['deliveryCorpSn'])['qj_name'];
                    $order['express_code']=$content['deliveryCorpSn'];
                    $order['express_no']=$content['deliverySn'];
                    $affect=$order->allowField(true)->save();
                    $log['result']=$affect?'订单商品修改发货信息成功;':'订单商品修改发货信息失败;';
                    //只要修改，则把订单发货信息修改录入微信商户平台,这个好像不需要
                    /*$result = $this->uploadShippingInfo($order);
                    if ($result['code'] == 0) {//成功
                        $log['result'] .= ',小程序发货信息修改上传成功';
                        $order['mch_platform_status'] = 1;
                        $affect = $order->allowField(true)->save();
                        $log['result'] .= $affect ? ',状态更新成功' : ',状态更新失败';
                    } else {//失败
                        $log['result'] .= ',小程序发货信息修改上传失败';
                    }*/
                }else{
                    $log['result']='失败:订单不存在;';
                }
                break;


            //商品类消息类型
            case 4://商品基础信息或商品状态变更通知,关联的商品基础信息或商品状态变更,{"spuId":1400300744143876097}
                $log['type']='商品基础信息或商品状态变更';
                $goods=model('app\common\model\wanlshop\Goods')->where('spuId',$content['spuId'])->find();
                //全境供应链云-查询SPU商品详情
                $spuListAll=getSpuBySpuIds([[$content['spuId']]]);
                if(isset($spuListAll['code'])){
                    $log['result']='查询SPU商品详情报错:'.$spuListAll['msg'].';';
                }else {
                    $spuInfo = $spuListAll ? $spuListAll[0] : [];
                    if ($spuInfo) {
                        $goodsData = [
                            'id'=>$goods['id'],
                            'category_id' => $spuInfo['categoryId3'] ?? ($spuInfo['categoryId2'] ?? $spuInfo['categoryId1']),
                            'brand_id' => $spuInfo['brandId'],
                            'title' => $spuInfo['name'],
                            'image' => $spuInfo['carouselImgList'] ? $spuInfo['carouselImgList'][0] : ($spuInfo['detailImgList'] ? $spuInfo['detailImgList'][0] : ''),
                            'images' =>$spuInfo['carouselImgList'] ? implode(',', $spuInfo['carouselImgList']) : '',
                            'description' => '',
                            'content' =>$spuInfo['detailImgList'] ? implode(',', $spuInfo['detailImgList']):'',
                            'freeExpress' => $spuInfo['freeExpress'],
                            'status' => $spuInfo['status'] ? 'hidden' : 'normal'//status	商品状态：0、已上架1、已下架
                        ];
                        //更新商品
                        $result=$goods->update($goodsData);
                        ////全境供应链-获取商品规格信息，有必要重新获取商品的库存信息(有可能商品库存发生了改变)
                        $log['result'] =$result?$this->fetch_goods_sku($goods):'商品基础信息更新失败;';
                    } else {
                        $log['result'] = '失败:未查询到商品详情;';
                    }
                }
                break;
            case 5://商品删除通知,关联的商品spu删除,{"spuId":1402510136427200513}
                $log['type']='商品删除通知';
                $goods=model('app\index\model\wanlshop\Goods')->where('spuId',$content['spuId'])->find();
                Db::startTrans();
                try{
                    model('app\index\model\wanlshop\GoodsSpu')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsSku')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsComment')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsFollow')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\OrderGoods')->where('goods_id',$goods['id'])->delete(true);
                    $goods->delete(true);
                    Db::commit();
                    $log['result']='成功;';
                }catch (\Exception $e){
                    Db::rollback();
                    $log['result']='失败:'.$e->getMessage().';';
                }
                break;
            case 6://商品规格删除通知,商品规格删除,{"spuId":1410802627445850113, "skuId":1412606164546945025}
                $log['type']='商品规格删除通知';
                $result=model('app\index\model\wanlshop\GoodsSku')->where($content)->delete(true);
                $log['result']=$result?'成功;':'失败;';
                break;
            case 7://商品规格变更通知,商品规格变更,{"spuId":1410802627445850113, "skuId":1414508574131421186}
                $log['type']='商品规格变更通知';
                $goods=model('app\common\model\wanlshop\Goods')->where('spuId',$content['spuId'])->find();
                //全境供应链-获取商品规格信息
                $log['result']=$this->fetch_goods_sku($goods);
                break;
            case 8://选品库商品状态变更通知,关联的选品库商品spu被移出选品库,{"spuId":1400328058546237442}
                /*$log['type']='商品被移出选品库';
                $result=model('app\common\model\wanlshop\Goods')
                    ->where('spuId',$content['spuId'])
                    ->update(['status'=>'hidden']);
                $log['err']=$result?'':'状态更新失败';*/
                break;
            case 10://商品库选品变动通知,选品库商品spu被加入商品库，{"spuId":1400328058546237442}
                $log['type']='商品被加入商品库';
                $goodsData=[];
                //全境供应链云-查询SPU商品详
                $spuListAll=getSpuBySpuIds([[$content['spuId']]]);
                foreach ($spuListAll as $item) {
                    //status	商品状态：0、已上架1、已下架
                    $goodsData[] =$item['status']?[]:[
                        'spuId' => $item['spuId'],
                        'shop_id' =>1,//店铺ID
                        'shop_category_id' => 1,
                        'category_id' => $item['categoryId3'] ?? ($item['categoryId2'] ?? $item['categoryId1']),
                        'brand_id' => $item['brandId'],
                        'title' => $item['name'],
                        'image' => $item['carouselImgList'] ? $item['carouselImgList'][0] : ($item['detailImgList'] ? $item['detailImgList'][0] : ''),
                        'images' =>$item['carouselImgList'] ? implode(',', $item['carouselImgList']) : '',
                        'description' => '',
                        'content' =>$item['detailImgList'] ? implode(',', $item['detailImgList']) : '',
                        'freight_id' => 1,
                        'freeExpress' => $item['freeExpress']
                    ];
                }
                $result=$goodsData?model('app\common\model\wanlshop\Goods')->saveAll($goodsData,false):[];
                $log['result']=$result?$this->fetch_goods_sku($result[0]):'失败;';
                break;
            case 11://商品库选品变动通知,选品库商品spu被移出商品库
                $log['type']='商品被移出商品库';
                $goods=model('app\index\model\wanlshop\Goods')->where('spuId',$content['spuId'])->find();
                Db::startTrans();
                try{
                    model('app\index\model\wanlshop\GoodsSpu')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsSku')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsComment')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\GoodsFollow')->where('goods_id',$goods['id'])->delete(true);
                    model('app\index\model\wanlshop\OrderGoods')->where('goods_id',$goods['id'])->delete(true);
                    $goods->delete(true);
                    Db::commit();
                    $log['result']='成功;';
                }catch (\Exception $e){
                    Db::rollback();
                    $log['result']='失败:'.$e->getMessage().';';
                }
                break;
            case 12://选品库商品价格变更通知,企业商品库的商品sku分销价变更|企业商品库的商品sku市场价变更|企业商品库的商品sku销售指导价变更
                $log['type']=isset($content['officialDistriPrice'])?'市场价变更通知':(isset($content['suggestPrice'])?'销售指导价变更通知':'价格变更通知(非市场价变更,该条可忽略)');
                //市场价变更:{"officialDistriPrice":2.00,"spuId":1613411960935993346,"skuId":1613411960998907905}
                $result=1;
                $goods=model('app\index\model\wanlshop\Goods')->where('spuId',$content['spuId'])->find();
                if(isset($content['officialDistriPrice'])) {
                    $result = model('app\common\model\wanlshop\GoodsSku')
                        ->where('spuId', $content['spuId'])
                        ->where('skuId', $content['skuId'])
                        ->update([//在common.php中，我们把price和market_price都置为officialDistriPrice(市场价)了
                            'price'=>$content['officialDistriPrice'],
                            'market_price' => $content['officialDistriPrice']
                        ]);
                    $goods->update(['price'=>$content['officialDistriPrice']]);
                }

                //销售指导价变更:{"spuId":1613411960935993346,"skuId":1613411960998907905,"orgiSuggestPrice":13.90,"suggestPrice":14.9}
                /*if(isset($content['suggestPrice'])) {
                    $result = model('app\common\model\wanlshop\GoodsSku')
                        ->where('spuId', $content['spuId'])
                        ->where('skuId', $content['skuId'])
                        ->update(['price' => $content['suggestPrice']]);
                }*/
                $log['result']=(isset($result) && $result)?'成功;':'失败;';
                break;
            case 13://商品上下架通知,商品上下架,{"spuId":1651206730433220610,"status":1},status：0上架；1下架
                $status=[0=>'上架',1=>'下架'];
                $log['type']="商品{$status[$content['status']]}通知";
                $updateData=['status'=>$content['status']?'hidden':'normal'];
                $result=model('app\index\model\wanlshop\Goods')
                    ->where('spuId',$content['spuId'])
                    ->update($updateData);
                $log['result']=$result?"状态更新成功;":"状态更新失败,更新结果为{$result}(0表示无需更新);";
                break;
        }
        model('app\index\model\wanlshop\MessageLog')->create($log);
    }



    /**
     * 全境供应链-获取商品规格信息
     * @param \app\common\model\wanlshop\Goods $goods 商品实例
     * @return string
     */
    private function fetch_goods_sku(\app\common\model\wanlshop\Goods $goods):string{

        $skuData = $spuData = $goodsData = [];
        //全境供应链云-查询SKU规格信息
        $info = loadSkuInfoFromApi($goods, $skuData, $spuData);
        if(isset($info['code'])) return '失败:'.$info['msg'].',此时的goods为'.json_encode($goods);

        if ($info) {
            $skuData = array_merge($skuData, $info['skuData']);
            $spuData = array_merge($spuData, $info['spuData']);
            $goodsData[] = ['id' => $info['goods']['id'], 'price' => $info['goods']['price'],'hasspu'=>1];
        }

        if(!$skuData && !$spuData && !$goodsData) return '未查询到规格信息';
        $skuData = array_unique($skuData, SORT_REGULAR);
        $spuData = array_unique($spuData, SORT_REGULAR);

        $msg="Sku表,商品ID={$goods['id']},";
        $goodsSku=model('app\common\model\wanlshop\GoodsSku');
        $goodsSpu=model('app\common\model\wanlshop\GoodsSpu');

        //更新规格属性
        $sku_list=$goodsSku->where('goods_id',$goods['id'])->select();
        $cloud_skuids=array_column($skuData, 'skuId');
        $local_skuids=array_column($sku_list, 'skuId');
        //需要删除的skuid
        $delete_skuids=array_diff($local_skuids,$cloud_skuids);

        //新增的规格
        $newSkuData=[];
        foreach($skuData as $v){
            $exists=false;
            foreach($sku_list as $sku){
                if(($v['skuId']==$sku['skuId']) && ($v['goods_id']==$sku['goods_id'])){
                    $result=$sku->where('id',$sku['id'])->update($v);
                    $msg.=$result?"skuId={$v['skuId']}修改成功;":"skuId={$v['skuId']}修改结果为{$result}(0表示无需修改);";
                    $exists=true;
                }
            }
            if(!$exists)$newSkuData[]=$v;
        }

        Db::startTrans();
        try {
            //更新商品
            model('app\common\model\wanlshop\Goods')->saveAll($goodsData);
            //更新商品Sku
            if($newSkuData) {
                $result = $goodsSku->saveAll($newSkuData, false);
                $msg .= '新增结果为' . json_encode($result).';';
            }
            if($delete_skuids){
                $result=$goodsSku->where('goods_id', $goods['id'])
                    ->where('skuId', 'in', $delete_skuids)
                    ->delete(true);
                $msg.='删除结果为'.json_encode($result).';';
            }
            //更新商品Spu
            if(!$goodsSku->where('goods_id', $goods['id'])->count()){
                //如果没有了sku,则删除该商品的spu
                $result=$goodsSpu->where('goods_id', $goods['id'])->delete(true);
                $msg.='Spu表,删除结果为'.json_encode($result).';';
            }else{
                $spu = $spuData ? $goodsSpu->where('spuId', $spuData[0]['spuId'])
                    ->where('goods_id', $spuData[0]['goods_id'])
                    ->find() : null;
                if ($spu) {
                    $result = $spu->where('id', $spu['id'])->update($spuData[0]);
                    $msg .= "Spu表,修改ID={$spu['id']}结果为{$result}(0表示无需修改);";
                } else {
                    $result = $goodsSpu->saveAll($spuData, false);
                    $msg .= 'Spu表,新增结果为' . json_encode($result) . ',[]表示无新增;';
                }
            }
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            $msg='失败:异常为:'.$e->getMessage().';';
        }
        return $msg;
    }




    /**
     * 发货信息录入到微信商户平台
     * @param \app\api\model\wanlshop\Order $order 订单实例
     * @return array
     */
    private function uploadShippingInfo(\app\api\model\wanlshop\Order $order):array{
        //商品信息,可能有多个，这里只取一个
        $orderGoods=model('app\api\model\wanlshop\OrderGoods')
            ->where('order_id',$order['id'])
            ->where('status','normal')
            ->find();
        $orderGoodsCount=model('app\api\model\wanlshop\OrderGoods')
            ->where('order_id',$order['id'])
            ->where('status','normal')
            ->sum('number');
        if(!$orderGoods) return ['code'=>1,'msg'=>"订单ID={$order['id']},未找到订单商品信息"];

        //支付信息
        $pay=model('app\api\model\wanlshop\Pay')
            ->where('order_id',$order['id'])
            ->where('user_id',$order['user_id'])
            ->where('pay_state',1)
            ->where('status','normal')
            ->find();
        if(!$pay || !$pay['trade_no']) return ['code'=>1,'msg'=>"订单ID={$order['id']},未找到订单支付信息"];
        $payOutTrade=model('app\api\model\wanlshop\PayOutTrade')
            ->where('order_id',$order['id'])
            ->where('pay_id',$pay['id'])
            ->where('status','normal')
            ->find();
        if((bccomp($pay['used_balance'],$pay['price'])==0) && !$payOutTrade)
        return ['code'=>1,'msg'=>"订单ID={$order['id']},用的余额支付,无需上传到小程序"];
        if(!$payOutTrade) return ['code'=>1,'msg'=>"订单ID={$order['id']},支付单不存在,请检查"];

        //收件人信息
        $address=model('app\api\model\wanlshop\OrderAddress')
            ->where('order_id',$order['id'])
            ->where('user_id',$order['user_id'])
            ->where('shop_id',$order['shop_id'])
            ->where('status','normal')
            ->find();
        if(!$address || !$address['mobile']) return ['code'=>1,'msg'=>"订单ID={$order['id']},未找到订单收件人信息"];
        $receiver_mobile=substr($address['mobile'],0,3);
        $receiver_mobile.='****';
        $receiver_mobile.=substr($address['mobile'],-4);

        //用户微信信息
        $third = model('app\api\model\wanlshop\Third')
            ->get(['user_id' => $order['user_id']]);
        if(!$third || !$third['openid']) return ['code'=>1,'msg'=>"订单ID={$order['id']},未找到用户的openid"];

        //根据物流公司代码获取物流公司名称,['qj_name'=>'顺丰速运','wx_code'=>'SF','wx_name'=>'顺丰速运']
        $express_wx_code=getExpressNameByDeliveryCorpSn($order['express_code'])['wx_code'];
        if(!$express_wx_code) return ['code'=>1,'msg'=>"订单ID={$order['id']},腾讯端未匹配到全境的物流公司"];

        $orderData=[
            'order_key'=>[
                'order_number_type'=>2,//订单单号类型，用于确认需要上传详情的订单。枚举值1，使用下单商户号和商户侧单号；枚举值2，使用微信支付单号，必填:是
                'transaction_id'=>$pay['trade_no']//原支付交易对应的微信订单号，必填:否
            ],
            'logistics_type'=>1,//number	必填:是	物流模式，发货方式枚举值：1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品，虚拟商品，例如话费充值，点卡等，无实体配送形式 4、用户自提
            'delivery_mode'=>1,//number	必填:是	发货模式，发货模式枚举值：1、UNIFIED_DELIVERY（统一发货）2、SPLIT_DELIVERY（分拆发货） 示例值: UNIFIED_DELIVERY
            'shipping_list'=>[//array 必填:是	物流信息列表，发货物流单列表，支持统一发货（单个物流单）和分拆发货（多个物流单）两种模式，多重性: [1, 10]
                [
                    'tracking_no'=>$order['express_no'],//	string	必填:否	物流单号，物流快递发货时必填，示例值: 323244567777 字符字节限制: [1, 128]
                    'express_company'=>$express_wx_code,//	string	必填:否	物流公司编码，快递公司ID，参见「查询物流公司编码列表」，物流快递发货时必填， 示例值: DHL 字符字节限制: [1, 128]
                    'item_desc'=>"{$orderGoods['title']}等*{$orderGoodsCount}",//	string	必填:是	商品信息，例如：微信红包抱枕*1个，限120个字以内
                    'contact'=>[//	object	必填:否	联系方式，当发货的物流公司为顺丰时，联系方式为必填，收件人或寄件人联系方式二选一
                        //'consignor_contact'=>'',//	string	必填:否	寄件人联系方式，寄件人联系方式，采用掩码传输，最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
                        'receiver_contact'=>$receiver_mobile,//	string	必填:否	收件人联系方式，收件人联系方式为，采用掩码传输，最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
                    ]
               ]
            ],
            'upload_time'=>date('c'),//	string	必填:是	上传时间，用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00
            'payer'=>[//	object	必填:是	支付者，支付者信息
                'openid'=>$third['openid']//	string	必填:是	用户标识，用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
            ]
        ];
       $result=upload_shipping_info($orderData);
       $result['msg']="订单ID={$order['id']},".$result['msg'];
       return $result;
    }


}
